package modbusGreen

import (
	"io"
	"log"
	"os"
)

//Log 日志
//type Log struct {
//	log *logs.BeeLogger
//}

//初始化日志定义
var (
	Info 		*log.Logger
	Warning		*log.Logger
	Error		*log.Logger

)

func init() {
	initLog("log/err_log.log", "log/info_log.log", "log/warning_log.log")
}

func initLog(errs, info, warning string) {
	// create errFile
	errFile, err := os.OpenFile(errs, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
	if err != nil {
		log.Fatalln("open log file error: ", err)
	}

	infoFile, err := os.OpenFile(info, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
	if err != nil {
		log.Fatalln("open log file error: ", err)
	}

	warningFile, err := os.OpenFile(warning, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666)
	if err != nil {
		log.Fatalln("open log file error: ", err)
	}

	// set log info format
	Info = log.New(infoFile, "Info: ", log.Ldate | log.Ltime | log.Lshortfile)
	Warning = log.New(warningFile, "Warning: ", log.Ldate | log.Ltime | log.Lshortfile)
	Error = log.New(io.MultiWriter(os.Stderr, errFile), "Error: ", log.Ldate | log.Ltime | log.Lshortfile)

}


